// import 'babel-polyfill'
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import moment from "moment";
import "element-ui/lib/theme-chalk/index.css";
import "css/common/reset.css";
import "css/common/default-style.less";
import "css/common/element-reset.less";
import "css/common/classes.less";
import "css/common/btn.less";
import "./assets/font/font/iconfont.css";
import * as directive from "./utils/directives";
import warp from "@/components/warp";
import moduleHead from "@/components/moduleHead.vue";

Vue.config.productionTip = false;

ElementUI.Dialog.props.closeOnClickModal.default = false;

Vue.use(ElementUI, {
  // size: "small",
  zIndex: 3000,
});

Vue.filter("dateformat", function (dataStr, pattern = "YYYY-MM-DD HH:mm:ss") {
  return moment(dataStr).format(pattern);
});

/* 路由首位配置 */
let path = [];
let getRoutes = router.options.routes;

function getAllPath(router, arr) {
  router.forEach((item) => {
    if (item.name && arr.indexOf(item.name) == -1) {
      arr.push(item.name);
    }
    if (item.children && item.children.length > 0) {
      getAllPath(item.children, arr);
    }
  });
}

getAllPath(getRoutes, path);
router.beforeEach((to, from, next) => {
  if (path.indexOf(to.name) > -1) {
    next();
  } else {
    next({ path: "/404" });
  }
});

Vue.directive("permission", directive.permission);

Vue.component("warp", warp);
Vue.component("moduleHead", moduleHead);

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
